package com.dykj.fireFighting.server.base.emergency.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.base.emergency.dto.EmergencyStaffDto;
import com.dykj.fireFighting.api.base.emergency.entity.EmergencyStaff;
import com.dykj.fireFighting.api.base.emergency.service.IEmergencyStaffService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.base.emergency.mapper.EmergencyStaffMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;


/**
 * @author zhengbo
 */
@Slf4j
@DubboService
public class EmergencyStaffServiceImpl extends BaseServiceImpl<EmergencyStaffMapper, EmergencyStaff> implements IEmergencyStaffService {
    @Override
    public PageVo<EmergencyStaff> queryList(EmergencyStaffDto emergencyStaffDto) {

        LambdaQueryWrapper<EmergencyStaff> emergencyStaf = new LambdaQueryWrapper<>();
        emergencyStaf.eq(EmergencyStaff::getCenterid,emergencyStaffDto.getCenterid());
        if (StringUtils.isNotBlank(emergencyStaffDto.getMobile())) {
            emergencyStaf.eq(EmergencyStaff::getMobile,emergencyStaffDto.getMobile());
        }
        if (StringUtils.isNotBlank(emergencyStaffDto.getUsername())) {
            emergencyStaf.like(EmergencyStaff::getUsername,emergencyStaffDto.getUsername());
        }
        if (StringUtils.isNotBlank(emergencyStaffDto.getSystemtype())) {
            emergencyStaf.eq(EmergencyStaff::getSystemtype,emergencyStaffDto.getSystemtype());
        }
        if (StringUtils.isNotBlank(emergencyStaffDto.getUnitid())) {
            emergencyStaf.eq(EmergencyStaff::getUnitid,emergencyStaffDto.getUnitid());
        }

        Page<EmergencyStaff> page = new Page<>();
        page.setCurrent(emergencyStaffDto.getPage());
        // 设置页大小
        page.setSize(emergencyStaffDto.getLimit());
        IPage<EmergencyStaff> ipage = this.page(page, emergencyStaf);
        return new PageVo<>(ipage);
    }

    //获取火警的报警人员
    @Override
    public List<EmergencyStaff> getByUnitid(String unitid) {
        LambdaQueryWrapper<EmergencyStaff> emergencyStaf = new LambdaQueryWrapper<>();
        emergencyStaf.eq(EmergencyStaff::getUnitid,unitid);
        emergencyStaf.eq(EmergencyStaff::getIsdel,0);
        emergencyStaf.like(EmergencyStaff::getSystemtype,"12345678901");
        List<EmergencyStaff> list =  this.list(emergencyStaf);
        return list;
    }

    //获取水设备的报警人员
    @Override
    public List<EmergencyStaff> getWaterStaffByUnitid(String unitid) {
        LambdaQueryWrapper<EmergencyStaff> emergencyStaf = new LambdaQueryWrapper<>();
        emergencyStaf.eq(EmergencyStaff::getUnitid,unitid);
        emergencyStaf.eq(EmergencyStaff::getIsdel,0);
        emergencyStaf.like(EmergencyStaff::getSystemtype,"12345678902");
        List<EmergencyStaff> list =  this.list(emergencyStaf);
        return list;
    }

//获取庄诚设备的报警人员
    @Override
    public List<EmergencyStaff> getZcStaffByUnitid(String unitid) {
        LambdaQueryWrapper<EmergencyStaff> emergencyStaf = new LambdaQueryWrapper<>();
        emergencyStaf.eq(EmergencyStaff::getUnitid,unitid);
        emergencyStaf.eq(EmergencyStaff::getIsdel,0);
        emergencyStaf.like(EmergencyStaff::getSystemtype,"12345678903");
        List<EmergencyStaff> list =  this.list(emergencyStaf);
        return list;
    }

}
